namespace QMVnSoft.SystemForms
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormCompanyEditor : FormControl
    {
        private BtnControl btnCancel;
        private BtnControl btnOk;
        private IContainer components;
        private bool ib_CheckAccepted;
        private LabelControl lblChu_Tk;
        private LabelControl lblDia_Chi;
        private LabelControl lblDia_Chi_E;
        private LabelControl lblMs_Thue;
        private LabelControl lblNgay_Bd_Ht;
        private LabelControl lblTen_Dvcs;
        private LabelControl lblTen_Dvcs_E;
        private LabelControl lblTen_NH;
        private LabelControl lblTen_TP;
        private LabelControl lblTk_NH;
        private CompanyDataAccess oDataAccess = new CompanyDataAccess();
        private DataTable oTable;
        private TextControl txtChu_Tk;
        private TextControl txtDia_Chi;
        private TextControl txtDia_Chi_E;
        private TextControl txtMs_Thue;
        private TextDate txtNgay_Bd_Ht;
        private TextControl txtTen_Dvcs;
        private TextControl txtTen_Dvcs_E;
        private TextControl txtTen_NH;
        private TextControl txtTen_TP;
        private TextControl txtTk_NH;

        public FormCompanyEditor()
        {
            this.InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            this.OnSave();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.btnOk = new BtnControl();
            this.btnCancel = new BtnControl();
            this.lblTen_Dvcs = new LabelControl();
            this.txtTen_Dvcs = new TextControl();
            this.lblTen_Dvcs_E = new LabelControl();
            this.txtTen_Dvcs_E = new TextControl();
            this.lblDia_Chi = new LabelControl();
            this.txtDia_Chi = new TextControl();
            this.lblMs_Thue = new LabelControl();
            this.txtMs_Thue = new TextControl();
            this.lblTk_NH = new LabelControl();
            this.txtTk_NH = new TextControl();
            this.lblChu_Tk = new LabelControl();
            this.txtChu_Tk = new TextControl();
            this.lblTen_NH = new LabelControl();
            this.txtTen_NH = new TextControl();
            this.lblTen_TP = new LabelControl();
            this.txtTen_TP = new TextControl();
            this.lblNgay_Bd_Ht = new LabelControl();
            this.txtNgay_Bd_Ht = new TextDate();
            this.lblDia_Chi_E = new LabelControl();
            this.txtDia_Chi_E = new TextControl();
            base.SuspendLayout();
            this.btnOk.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.btnOk.Font = new Font("Arial", 8.25f);
            this.btnOk.Location = new Point(0x11b, 0xc6);
            this.btnOk.Name = "btnOk";
            this.btnOk.Size = new Size(0x4b, 0x17);
            this.btnOk.TabIndex = 10;
            this.btnOk.Text = "&Chấp nhận";
            this.btnOk.UseVisualStyleBackColor = true;
            this.btnOk.Click += new EventHandler(this.btnOk_Click);
            this.btnCancel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            //this.btnCancel.DialogResult = DialogResult.Cancel;
            this.btnCancel.Font = new Font("Arial", 8.25f);
            this.btnCancel.Location = new Point(0x16c, 0xc6);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(0x4b, 0x17);
            this.btnCancel.TabIndex = 11;
            this.btnCancel.Text = "&Hủy bỏ";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
            this.lblTen_Dvcs.AutoSize = true;
            this.lblTen_Dvcs.Font = new Font("Arial", 8.25f);
            this.lblTen_Dvcs.Location = new Point(9, 9);
            this.lblTen_Dvcs.Name = "lblTen_Dvcs";
            this.lblTen_Dvcs.Size = new Size(0x3a, 14);
            this.lblTen_Dvcs.TabIndex = 1;
            this.lblTen_Dvcs.Text = "Tên đơn vị";
            this.txtTen_Dvcs.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Dvcs.DisabledForeColor = Color.Empty;
            this.txtTen_Dvcs.Font = new Font("Arial", 8.25f);
            this.txtTen_Dvcs.Location = new Point(0x62, 6);
            this.txtTen_Dvcs.Name = "txtTen_Dvcs";
            this.txtTen_Dvcs.Size = new Size(0x155, 20);
            this.txtTen_Dvcs.TabIndex = 0;
            this.lblTen_Dvcs_E.AutoSize = true;
            this.lblTen_Dvcs_E.Font = new Font("Arial", 8.25f);
            this.lblTen_Dvcs_E.Location = new Point(9, 0x20);
            this.lblTen_Dvcs_E.Name = "lblTen_Dvcs_E";
            this.lblTen_Dvcs_E.Size = new Size(0x4a, 14);
            this.lblTen_Dvcs_E.TabIndex = 1;
            this.lblTen_Dvcs_E.Text = "Tên tiếng Anh";
            this.txtTen_Dvcs_E.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Dvcs_E.DisabledForeColor = Color.Empty;
            this.txtTen_Dvcs_E.Font = new Font("Arial", 8.25f);
            this.txtTen_Dvcs_E.Location = new Point(0x62, 0x1d);
            this.txtTen_Dvcs_E.Name = "txtTen_Dvcs_E";
            this.txtTen_Dvcs_E.Size = new Size(0x155, 20);
            this.txtTen_Dvcs_E.TabIndex = 1;
            this.lblDia_Chi.AutoSize = true;
            this.lblDia_Chi.Font = new Font("Arial", 8.25f);
            this.lblDia_Chi.Location = new Point(9, 0x37);
            this.lblDia_Chi.Name = "lblDia_Chi";
            this.lblDia_Chi.Size = new Size(40, 14);
            this.lblDia_Chi.TabIndex = 1;
            this.lblDia_Chi.Text = "Địa chỉ";
            this.txtDia_Chi.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtDia_Chi.DisabledForeColor = Color.Empty;
            this.txtDia_Chi.Font = new Font("Arial", 8.25f);
            this.txtDia_Chi.Location = new Point(0x62, 0x34);
            this.txtDia_Chi.Name = "txtDia_Chi";
            this.txtDia_Chi.Size = new Size(0x155, 20);
            this.txtDia_Chi.TabIndex = 2;
            this.lblMs_Thue.AutoSize = true;
            this.lblMs_Thue.Font = new Font("Arial", 8.25f);
            this.lblMs_Thue.Location = new Point(9, 0x65);
            this.lblMs_Thue.Name = "lblMs_Thue";
            this.lblMs_Thue.Size = new Size(60, 14);
            this.lblMs_Thue.TabIndex = 1;
            this.lblMs_Thue.Text = "Mã số thuế";
            this.txtMs_Thue.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtMs_Thue.CharacterCasing = CharacterCasing.Upper;
            this.txtMs_Thue.DisabledForeColor = Color.Empty;
            this.txtMs_Thue.Font = new Font("Arial", 8.25f);
            this.txtMs_Thue.Location = new Point(0x62, 0x62);
            this.txtMs_Thue.Name = "txtMs_Thue";
            this.txtMs_Thue.Size = new Size(0x72, 20);
            this.txtMs_Thue.TabIndex = 4;
            this.lblTk_NH.AutoSize = true;
            this.lblTk_NH.Font = new Font("Arial", 8.25f);
            this.lblTk_NH.Location = new Point(0xf3, 0x65);
            this.lblTk_NH.Name = "lblTk_NH";
            this.lblTk_NH.Size = new Size(0x55, 14);
            this.lblTk_NH.TabIndex = 1;
            this.lblTk_NH.Text = "T.Khoản N.hàng";
            this.txtTk_NH.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTk_NH.CharacterCasing = CharacterCasing.Upper;
            this.txtTk_NH.DisabledForeColor = Color.Empty;
            this.txtTk_NH.Font = new Font("Arial", 8.25f);
            this.txtTk_NH.Location = new Point(0x145, 0x62);
            this.txtTk_NH.Name = "txtTk_NH";
            this.txtTk_NH.Size = new Size(0x72, 20);
            this.txtTk_NH.TabIndex = 5;
            this.lblChu_Tk.AutoSize = true;
            this.lblChu_Tk.Font = new Font("Arial", 8.25f);
            this.lblChu_Tk.Location = new Point(9, 0x7c);
            this.lblChu_Tk.Name = "lblChu_Tk";
            this.lblChu_Tk.Size = new Size(0x48, 14);
            this.lblChu_Tk.TabIndex = 1;
            this.lblChu_Tk.Text = "Chủ tài khoản";
            this.txtChu_Tk.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtChu_Tk.DisabledForeColor = Color.Empty;
            this.txtChu_Tk.Font = new Font("Arial", 8.25f);
            this.txtChu_Tk.Location = new Point(0x62, 0x79);
            this.txtChu_Tk.Name = "txtChu_Tk";
            this.txtChu_Tk.Size = new Size(0x155, 20);
            this.txtChu_Tk.TabIndex = 6;
            this.lblTen_NH.AutoSize = true;
            this.lblTen_NH.Font = new Font("Arial", 8.25f);
            this.lblTen_NH.Location = new Point(9, 0x93);
            this.lblTen_NH.Name = "lblTen_NH";
            this.lblTen_NH.Size = new Size(0x4f, 14);
            this.lblTen_NH.TabIndex = 1;
            this.lblTen_NH.Text = "Tên ngân hàng";
            this.txtTen_NH.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_NH.DisabledForeColor = Color.Empty;
            this.txtTen_NH.Font = new Font("Arial", 8.25f);
            this.txtTen_NH.Location = new Point(0x62, 0x90);
            this.txtTen_NH.Name = "txtTen_NH";
            this.txtTen_NH.Size = new Size(0x155, 20);
            this.txtTen_NH.TabIndex = 7;
            this.lblTen_TP.AutoSize = true;
            this.lblTen_TP.Font = new Font("Arial", 8.25f);
            this.lblTen_TP.Location = new Point(9, 170);
            this.lblTen_TP.Name = "lblTen_TP";
            this.lblTen_TP.Size = new Size(0x3a, 14);
            this.lblTen_TP.TabIndex = 1;
            this.lblTen_TP.Text = "Thành phố";
            this.txtTen_TP.DisabledForeColor = Color.Empty;
            this.txtTen_TP.Font = new Font("Arial", 8.25f);
            this.txtTen_TP.Location = new Point(0x62, 0xa7);
            this.txtTen_TP.Name = "txtTen_TP";
            this.txtTen_TP.Size = new Size(0x72, 20);
            this.txtTen_TP.TabIndex = 8;
            this.lblNgay_Bd_Ht.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.lblNgay_Bd_Ht.AutoSize = true;
            this.lblNgay_Bd_Ht.Font = new Font("Arial", 8.25f);
            this.lblNgay_Bd_Ht.Location = new Point(0xec, 170);
            this.lblNgay_Bd_Ht.Name = "lblNgay_Bd_Ht";
            this.lblNgay_Bd_Ht.Size = new Size(0x7a, 14);
            this.lblNgay_Bd_Ht.TabIndex = 3;
            this.lblNgay_Bd_Ht.Text = "Ngày bắt đầu hạch toán";
            this.txtNgay_Bd_Ht.Font = new Font("Arial", 8.25f);
            this.txtNgay_Bd_Ht.Location = new Point(0x167, 0xa7);
            this.txtNgay_Bd_Ht.Name = "txtNgay_Bd_Ht";
            this.txtNgay_Bd_Ht.Size = new Size(80, 20);
            this.txtNgay_Bd_Ht.TabIndex = 9;
            this.lblDia_Chi_E.AutoSize = true;
            this.lblDia_Chi_E.Font = new Font("Arial", 8.25f);
            this.lblDia_Chi_E.Location = new Point(9, 0x4e);
            this.lblDia_Chi_E.Name = "lblDia_Chi_E";
            this.lblDia_Chi_E.Size = new Size(0x59, 14);
            this.lblDia_Chi_E.TabIndex = 1;
            this.lblDia_Chi_E.Text = "Địa chỉ tiếng Anh";
            this.txtDia_Chi_E.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtDia_Chi_E.DisabledForeColor = Color.Empty;
            this.txtDia_Chi_E.Font = new Font("Arial", 8.25f);
            this.txtDia_Chi_E.Location = new Point(0x62, 0x4b);
            this.txtDia_Chi_E.Name = "txtDia_Chi_E";
            this.txtDia_Chi_E.Size = new Size(0x155, 20);
            this.txtDia_Chi_E.TabIndex = 3;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.CancelButton = this.btnCancel;
            base.ClientSize = new Size(0x1c3, 0xe9);
            base.Controls.Add(this.txtNgay_Bd_Ht);
            base.Controls.Add(this.lblNgay_Bd_Ht);
            base.Controls.Add(this.txtTen_TP);
            base.Controls.Add(this.lblTen_TP);
            base.Controls.Add(this.txtTen_NH);
            base.Controls.Add(this.lblTen_NH);
            base.Controls.Add(this.txtChu_Tk);
            base.Controls.Add(this.lblChu_Tk);
            base.Controls.Add(this.txtTk_NH);
            base.Controls.Add(this.lblTk_NH);
            base.Controls.Add(this.txtMs_Thue);
            base.Controls.Add(this.lblMs_Thue);
            base.Controls.Add(this.txtDia_Chi_E);
            base.Controls.Add(this.lblDia_Chi_E);
            base.Controls.Add(this.txtDia_Chi);
            base.Controls.Add(this.lblDia_Chi);
            base.Controls.Add(this.txtTen_Dvcs_E);
            base.Controls.Add(this.lblTen_Dvcs_E);
            base.Controls.Add(this.txtTen_Dvcs);
            base.Controls.Add(this.lblTen_Dvcs);
            base.Controls.Add(this.btnCancel);
            base.Controls.Add(this.btnOk);
            //base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "FormCompanyEditor";
            base.ShowInTaskbar = false;
            this.Text = "Thông tin đơn vị cơ sở";
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void OnSave()
        {
            if (!AppInstance.TaxCodeValidate(this.txtMs_Thue.Value))
            {
                MessageBox.Show("Mã số thuế không chính xác!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                this.CheckAccepted = true;
                this.oTable.Rows[0]["Ten_Dvcs"] = this.txtTen_Dvcs.Text;
                this.oTable.Rows[0]["Ten_Dvcs_E"] = this.txtTen_Dvcs_E.Text;
                this.oTable.Rows[0]["Dia_Chi"] = this.txtDia_Chi.Text;
                this.oTable.Rows[0]["Dia_Chi_E"] = this.txtDia_Chi_E.Text;
                this.oTable.Rows[0]["Ms_Thue"] = this.txtMs_Thue.Text;
                this.oTable.Rows[0]["Tk_NH"] = this.txtTk_NH.Text;
                this.oTable.Rows[0]["Chu_Tk"] = this.txtChu_Tk.Text;
                this.oTable.Rows[0]["Ten_NH"] = this.txtTen_NH.Text;
                this.oTable.Rows[0]["Ten_TP"] = this.txtTen_TP.Text;
                this.oTable.Rows[0]["Ngay_Bd_Ht"] = this.txtNgay_Bd_Ht.Text;
                this.oDataAccess.SetCompany(this.oTable.Rows[0]);
                base.Close();
            }
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys.Control | Keys.Return))
            {
                this.OnSave();
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        public bool CheckAccepted
        {
            get
            {
                return this.ib_CheckAccepted;
            }
            set
            {
                this.ib_CheckAccepted = value;
            }
        }

        public string CompanyCode
        {
            set
            {
                this.oTable = this.oDataAccess.GetCompanies(value);
                this.txtTen_Dvcs.Text = (string) this.oTable.Rows[0]["Ten_Dvcs"];
                this.txtTen_Dvcs_E.Text = (string) this.oTable.Rows[0]["Ten_Dvcs_E"];
                this.txtDia_Chi.Text = (string) this.oTable.Rows[0]["Dia_Chi"];
                this.txtDia_Chi_E.Text = (string) this.oTable.Rows[0]["Dia_Chi_E"];
                this.txtMs_Thue.Text = (string) this.oTable.Rows[0]["Ms_Thue"];
                this.txtTk_NH.Text = (string) this.oTable.Rows[0]["Tk_NH"];
                this.txtChu_Tk.Text = (string) this.oTable.Rows[0]["Chu_Tk"];
                this.txtTen_NH.Text = (string) this.oTable.Rows[0]["Ten_NH"];
                this.txtTen_TP.Text = (string) this.oTable.Rows[0]["Ten_TP"];
                this.txtNgay_Bd_Ht.Text = ((DateTime) this.oTable.Rows[0]["Ngay_Bd_Ht"]).ToShortDateString();
            }
        }

        public string CompanyFullName
        {
            get
            {
                return this.txtTen_Dvcs.Text;
            }
        }

        public string StartDate
        {
            get
            {
                return this.txtNgay_Bd_Ht.Text;
            }
        }
    }
}

